package com.zw.chat.common.context;

import org.springframework.ai.chat.messages.Message;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author by: zyl
 * @ClassName: MessageContext
 * @Description: 消息上下文
 * @Date: 2024/12/6 20:36
 */
public class MessageContext {

    private static final Map<String, LinkedList<Message>> MESSAGE_MAP = new ConcurrentHashMap<>();


    public static LinkedList<Message> getMessage(String sessionId) {
        return MESSAGE_MAP.getOrDefault(sessionId, new LinkedList<>());
    }

    public static void addMessage(String sessionId, LinkedList<Message> messages) {
        MESSAGE_MAP.put(sessionId, messages);
    }

    public static void rmMessage(String sessionId) {
        MESSAGE_MAP.remove(sessionId);
    }

    public static boolean exists(String sessionId) {
        return MESSAGE_MAP.containsKey(sessionId);
    }
}
